package cn.zktr.Personnel.controllers.zhouyongcong.end;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.zktr.Personnel.model.pojos.PerAudit;
import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.getUitlsService;
import cn.zktr.Personnel.model.service.zhouyongcong.savePojosService;
import cn.zktr.Personnel.model.service.zhouyongcong.end.socialService;
import cn.zktr.Personnel.model.service.zhouyongcong.monit.monitfindService;
import cn.zktr.Personnel.model.uitls.Wle;

@Controller
public class socialController {
	@Autowired
	private getUitlsService gus;
	@Autowired
	private findService fs;
	@Autowired
	private savePojosService ms;
	@Autowired
	private monitfindService mn_s;
	@Autowired
	private socialService sos;
	
	@RequestMapping("Kno_wle")
	@ResponseBody
	public List<Wle> Kno_wle(HttpSession session) {
		Object obj = session.getAttribute("id");
		return gus.getWle(Integer.valueOf(obj+""));
	}
	
	@RequestMapping("Bel_wle")
	@ResponseBody
	public List<Map<String,Object>> Bel_wle(HttpSession session) {
		
		List<PerPmsEmp> list = sos.Bel_wle(Integer.valueOf(session.getAttribute("id")+""));
		List<Map<String,Object>> list_map = new ArrayList<>();
		for(PerPmsEmp pe : list) {
			Map<String,Object> map=new HashMap<>();
			map.put("empid",pe.getEmpid());
			map.put("empimg",pe.getPerPmsZts().get(0).getZthost());
			map.put("potzw",pe.getPerPmsStms().get(0).getPerPmsPot().getPotzw());
			map.put("empname",pe.getEmpname());
			list_map.add(map);
		}
		return list_map;
	}
	
	@RequestMapping("Aud_wle")
	@ResponseBody
	public List<Map<String,Object>> Aud_wle(HttpSession session) {
		Object obj = session.getAttribute("id");
		PerPmsEmp ppe = fs.findEmpid(Integer.valueOf(obj+""));
		List<PerAudit> list = ppe.getPerAudits2();
		List<Map<String,Object>> list_map = new ArrayList<>();
		for(PerAudit pa : list) {
			Map<String,Object> map=new HashMap<>();
			map.put("id",pa.getAuditid());
			map.put("audempname",pa.getPerPmsEmp1().getEmpname());
			map.put("audempimg",pa.getPerPmsEmp1().getPerPmsZts().get(0).getZthost());
			map.put("auditjg",pa.getAuditjg());
			map.put("auditrem",pa.getAuditrem());
			map.put("auditsjid",pa.getAuditsj());
			if(pa.getAuditjg().equals("待处理")) {
				list_map.add(map);
			}
		}
		return list_map;
	}
	
	@RequestMapping("Aud_true")
	@ResponseBody
	public void Aud_true(int id) {
		PerAudit pa = fs.findAuditid(id);
		if(pa.getPerAuditShlx1()!=null) {
			mn_s.save_audit(pa);
		}else {
			mn_s.find(pa.getPerAuditMdies());
		}
		pa.setAuditjg("已通过");
		ms.modif_Audit(pa);
	}
	@RequestMapping("Aud_false")
	@ResponseBody
	public void Aud_false(int id) {
		PerAudit pa = fs.findAuditid(id);
		pa.setAuditjg("不通过");
		ms.modif_Audit(pa);
	}
}
